package com.thead;

/**
 * 每个线程输出不同的数字
 */
public class OftenThread extends Thread {

    public static void main(String[] args) throws InterruptedException {

        Thread thread;
        Thread thread1;
        Thread thread2;
        Thread thread3;
        int count =1;
        for(int i= 1; i<= 10; i++){
            for(int j = 1; j <= 4; j++){
                synchronized (args){
                if(j==1){
                    thread = new Thread(new OutPutThread(count, "线程1"));
                    thread.start();
                    thread.join(); //保证线程的有序性
                }
                if(j==2){
                    thread1 = new Thread(new OutPutThread(count,"线程2"));
                    thread1.start();
                    thread1.join();
                }
                if(j==3){
                    thread2 = new Thread(new OutPutThread(count,"线程3"));
                    thread2.start();
                    thread2.join();
                }
                if(j==4){
                    thread3 = new Thread(new OutPutThread(count,"线程4"));
                    thread3.start();
                    thread3.join();

                }
                    count = getCount(count);
                }
            }
        }

    }

    private static int getCount(int count){
        return count + 2;
    }

}
